<?php
ob_clean();
header("content-type:text/html;charset=utf-8");
include_once ("/Classes/PHPExcel.php");
$pdo=new PDO("mysql:host=127.0.0.1;dbname=bok;charset=utf8",'root','root');
$sql="select * from ke";
$res=$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$excel=new PHPExcel();
$sheet=$excel->setActiveSheetIndex(0);
$sheet->setCellValue('A1','ID')
      ->setCellValue('B1','名称')
      ->setCellValue('C1','时间')
      ->setCellValue('D1','数量')
      ->setCellValue('E1','教室');
$i=2;
foreach ($res as $key=>$value)
{
    $sheet->setCellValue('A'.$i,$value['id'])
          ->setCellValue('B'.$i,$value['name'])
          ->setCellValue('C'.$i,$value['shi'])
          ->setCellValue('D'.$i,$value['shu'])
          ->setCellValue('E'.$i,$value['jiao'])->getDefaultStyle()->getFont()->setSize(10);
    $i++;
}

    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="01simple.xls"');
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
    $objWriter->save('php://output');
    exit;




?>